Imports NUnit.Framework

<TestFixture()> _
Public Class nunit_test_IBANSynthesis

    <TestFixtureSetUp()> _
    Public Sub Init()
        IBANDefinitions.ReadDefinitions("..\..\IBANFuncsCore\IBANDefinitions.xml")
    End Sub

    <TestFixtureTearDown()> _
    Public Sub Cleanup()
    End Sub

    <Test()> _
    Public Sub TestAustriaIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("AT"))
    End Sub

    <Test()> _
    Public Sub TestAndorraIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("AD"))
    End Sub

    <Test()> _
    Public Sub TestBelgiumIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("BE"))
    End Sub

    <Test()> _
    Public Sub TestCroatiaIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("HR"))
    End Sub

    <Test()> _
    Public Sub TestCyprusIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("CY"))
    End Sub

    <Test()> _
    Public Sub TestCzechRepublicIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("CZ"))
    End Sub

    <Test()> _
    Public Sub TestDenmarkIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("DK"))
    End Sub

    <Test()> _
    Public Sub TestEstoniaIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("EE"))
    End Sub

    <Test()> _
    Public Sub TestFinlandIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("FI"))
    End Sub

    <Test()> _
    Public Sub TestFranceIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("FR"))
    End Sub

    <Test()> _
    Public Sub TestGermanyIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("DE"))
    End Sub

    <Test()> _
    Public Sub TestGibraltarIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("GI"))
    End Sub

    <Test()> _
    Public Sub TestGreeceIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("GR"))
    End Sub

    <Test()> _
    Public Sub TestHungaryIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("HU"))
    End Sub

    <Test()> _
    Public Sub TestIcelandIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("IS"))
    End Sub

    <Test()> _
    Public Sub TestIrelandIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("IE"))
    End Sub

    <Test()> _
    Public Sub TestItalyIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("IT"))
    End Sub

    <Test()> _
    Public Sub TestLatviaIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("LV"))
    End Sub

    <Test()> _
    Public Sub TestLiechtensteinIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("LI"))
    End Sub

    <Test()> _
    Public Sub TestLithuaniaIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("LT"))
    End Sub

    <Test()> _
    Public Sub TestLuxembourgIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("LU"))
    End Sub

    <Test()> _
    Public Sub TestMaltaIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("MT"))
    End Sub

    <Test()> _
    Public Sub TestNetherlandIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("NL"))
    End Sub

    <Test()> _
    Public Sub TestNorwayIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("NO"))
    End Sub

    <Test()> _
    Public Sub TestPolandIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("PL"))
    End Sub

    <Test()> _
    Public Sub TestPortugalIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("PT"))
    End Sub

    <Test()> _
    Public Sub TestRomaniaIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("RO"))
    End Sub

    <Test()> _
    Public Sub TestSlovakRepublicIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("SK"))
    End Sub

    <Test()> _
    Public Sub TestSloveniaIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("SI"))
    End Sub

    <Test()> _
    Public Sub TestSpainIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("ES"))
    End Sub

    <Test()> _
    Public Sub TestSwedenIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("SE"))
    End Sub

    <Test()> _
    Public Sub TestSwitzerlandIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("CH"))
    End Sub

    <Test()> _
    Public Sub TestTunisiaIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("TN"))
    End Sub

    <Test()> _
    Public Sub TestUnitedKingdomIBANSynthesis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("GB"))
    End Sub

    <Test()> _
    Public Sub TestBosniaHergezegovinaIBANAnalysis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("BA"))
    End Sub

    <Test()> _
    Public Sub TestBulgariaIBANAnalysis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("BG"))
    End Sub

    <Test()> _
    Public Sub TestMacedoniaIBANAnalysis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("MK"))
    End Sub

    <Test()> _
    Public Sub TestMontenegroIBANAnalysis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("ME"))
    End Sub

    <Test()> _
    Public Sub TestSerbiaIBANAnalysis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("RS"))
    End Sub

    <Test()> _
    Public Sub TestTurkeyIBANAnalysis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("TR"))
    End Sub

    <Test()> _
    Public Sub TestMauritiusIBANAnalysis()
        TestIBANSynthesis(nunit.nunit_const.FindElementIndex("MU"))
    End Sub

    <Test()> _
    Public Sub Test_NumericCharacterException()
        Try
            IBANCreator.CreateIBAN(New IBANContents("FR", "", "20041", "01005", "0500013002606"), True)
            Assert.Fail("No exception (expected XIBANNumericCharacterException)")
        Catch ex As XIBANNumericCharacterException
        Catch ex As Exception
            Assert.Fail("Invalid exception (expected XIBANNumericCharacterException), " + ex.ToString())
        End Try
    End Sub

    <Test()> _
    Public Sub Test_InvalidCountryException()
        Try
            IBANCreator.CreateIBAN(New IBANContents("ZZ", "", "20041", "01005", "0500013002606"), True)
            Assert.Fail("No exception (expected XIBANInvalidCountryCodeException)")
        Catch ex As XIBANInvalidCountryCodeException
        Catch ex As Exception
            Assert.Fail("Invalid exception (expected XIBANInvalidCountryCodeException), " + ex.ToString())
        End Try
    End Sub

    Private Sub TestIBANSynthesis(ByVal index As Integer)
        Try
            Dim IBAN As New IBANContents(nunit.nunit_const.IBANRecords(index).CountryCode, _
                                         "", _
                                         nunit.nunit_const.IBANRecords(index).BankCode, _
                                         nunit.nunit_const.IBANRecords(index).BranchCode, _
                                         nunit.nunit_const.IBANRecords(index).AccountNumber)
            Dim IBANStr As String = IBANCreator.CreateIBAN(IBAN, True)
            Console.WriteLine("IBAN Creator results")
            Console.WriteLine("=====================")
            Console.WriteLine("Country: " + IBAN.CountryCode)
            Console.WriteLine("Check digits: " + IBAN.CheckDigits)
            Console.WriteLine("Bank code: " + IBAN.BankCode)
            Console.WriteLine("Branch code: " + IBAN.BranchCode)
            Console.WriteLine("Account number: " + IBAN.AccountNumber)
            Console.WriteLine("IBAN: " + IBANStr)
            If IBANStr <> nunit.nunit_const.IBANRecords(index).IBANString Then
                Assert.Fail("Mismatched IBAN strings")
            End If
        Catch ex As Exception
            Console.WriteLine("Exception on TestIBANSynthesis (" + ex.ToString() + ")")
            Assert.Fail("Exception on TestIBANSynthesis (" + ex.ToString() + ")")
        End Try
    End Sub

End Class
